package com.my.blog.saToken;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/***
 *
 * @Auther: MuYun
 * @Date: 2022/4/8 16:39
 * @Description： SaToken自定义权限验证接口
 *
 */
@Component
public class SaTokenAuth implements StpInterface {

    private Logger logger= LoggerFactory.getLogger(this.getClass());

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        ArrayList<String> permissionList=new ArrayList<>();
        if(StpUtil.isLogin()){
            logger.info("赋予权限user");
            permissionList.add("user");
        }
        String id=(String)StpUtil.getLoginId();
        if("1".equals(id)){
            logger.info("赋予权限admin");
            permissionList.add("admin");
        }
        return permissionList;
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        return null;
    }
}
